using RockBus.DataContracts;
using RockBus.ServiceModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;

namespace RockBus.Hosting
{
    public class ReceivePortAddingMessageInspector : IDispatchMessageInspector
    {
        public ReceivePortAddingMessageInspector(PublisherReceivePortInfo publisherReceivePortInfo)
        {
            this.PublisherReceivePortInfo = publisherReceivePortInfo;
        }

        public PublisherReceivePortInfo PublisherReceivePortInfo { get; private set; }

        #region IDispatchMessageInspector Members

        public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
        {
            // Find where to put the
            request.Properties.SetPublisherReceivePortInfo(this.PublisherReceivePortInfo);
            return null;
        }

        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            // Intentionally left blank
        }

        #endregion IDispatchMessageInspector Members
    }
}